package com.heima.controller;


import com.heima.pojo.dto.UserQueryDTO;
import com.heima.pojo.entity.TbRole;
import com.heima.pojo.entity.TbUser;
import com.heima.pojo.vo.TbSkuPageVO;
import com.heima.pojo.vo.UserRoleVO;
import com.heima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user-service")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/user/search")
    public TbSkuPageVO<UserRoleVO> search(UserQueryDTO dto){
        return userService.search(dto);
    }
    @GetMapping("/role")
    public List<TbRole> insertRole(){
        return userService.insertRole();
    }
    @PostMapping("/user")
    public Boolean insertRole(@RequestBody TbUser tbUser){
        return userService.insertUser(tbUser);
    }

    @PutMapping("/user/{userId}")
    public Boolean updateUser(@PathVariable("userId") Long userId, @RequestBody TbUser tbUser){
        return userService.updateUser(userId,tbUser);
    }
    @DeleteMapping("/user/{userId}")
    public Boolean deleteUser(@PathVariable("userId") Long userId){
        return userService.deleteUser(userId);
    }



}
